#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
int l[maxn];
int r[maxn];
int st[maxn];
char s[maxn];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		cin>>s;
		int len = strlen(s);
		int lnum = 0;
		int rnum = 0;
		int stnum = 0;
		for(int i = 0;i<len;i++)
		{
			if(s[i]=='(') l[lnum++] = i;
			else if(s[i]=='*') st[stnum++] = i;
			else 
			{
				r[rnum++] = i;
				if(lnum)
				{
					lnum--;
					rnum--;
				}
			}
		}
		if((lnum||rnum)&&!stnum) 
		{
			printf("No solution!\n");
			continue;
		}
		int vis = stnum-1;
		int lcnt = 0;
		for(int i = 0;i<lnum;i++)
		{
			while(l[i]>st[vis]&&vis>=0) vis--;
			if(vis==-1) break;
			else 
			{
				s[st[vis]]=')';
				st[vis] = -1;
				lcnt++;
			}
		}
		lnum -= lcnt;
		int rcnt = 0;
		vis = 0;
		for(int i = rnum-1;i>=0;i--)
		{
			
			while(st[vis]==-1) vis++;
			while(r[i]<st[vis]&&vis<stnum) vis++;
			while(st[vis]==-1) vis++;
			if(vis==stnum) break;
			else 
			{
				s[st[vis]]='(';
				st[vis] = -1;
				rcnt++;
			}
		}
		rnum -= rcnt;
		if(rnum||lnum) printf("No solution!");
		else 
		for(int i = 0;i<len;i++)
		{
			if(s[i]=='*') continue;
			else printf("%c",s[i]);
		}
		printf("\n");
	}
}
